/***************************************************************************
 *   Copyright (C) 2005 by xihe   *
 *   xihels@163.com                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "QQUser.h"
#include "md5.h"
#include <string>


QQUser::QQUser() :
    uid(0),
    port(8000),
    loginMode(QQ_LOGIN_MODE_NORMAL),
    tcp(false),
    fakeCam(false){
	bzero(pwkey, sizeof (pwkey));
    }
QQUser::~QQUser(){}

QQUser::QQUser(const QQUser& rhs) : 
    uid(rhs.uid),
    server(rhs.server),
    port(rhs.port),
    loginMode(rhs.loginMode),
    tcp(rhs.tcp),
    rememberPassword(rhs.rememberPassword)
{
    memcpy(pwkey, rhs.pwkey, sizeof (pwkey));
}

QQUser& QQUser::operator = (const QQUser& rhs) {
    if (this != &rhs) {
	uid	  = rhs.uid;
	loginMode = rhs.loginMode;
	server	  = rhs.server;
	port	  = rhs.port;
	tcp	  = rhs.tcp;
	rememberPassword = rhs.rememberPassword;
	memcpy(pwkey, rhs.pwkey, sizeof (pwkey));
    }
    return *this;
}


void QQUser::genPwkey(const char* pwd, uint8_t* const key) {
    md5_state_t ctx;

    md5_init(&ctx);
    md5_append(&ctx, (const md5_byte_t*)pwd, strlen(pwd));
    md5_finish(&ctx, key);

    md5_init(&ctx);
    md5_append(&ctx, key, QQ_KEY_LENGTH);
    md5_finish(&ctx, key);
}

void QQUser::setPwkey(const uint8_t* _pwkey)
{
    memcpy(pwkey, _pwkey, QQ_KEY_LENGTH); 
}

